package com.education.controller.backend;

import com.education.common.JsonData;
import com.education.service.IFileService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.StringUtil;
import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @author 林心晨
 * @Title:
 * @Package
 * @Description:
 * @date create in 5.11  11:48
 */
@RequestMapping("/image/")
@Controller
public class FileController {

    @Autowired
    private IFileService iFileService ;

    @RequestMapping(value = "managePage",method = RequestMethod.GET)
    public ModelAndView imagePage(ModelAndView model){
        model.setViewName("image-list");
        return model;
    }

    @RequestMapping(value = "image_add",method = RequestMethod.GET)
    public ModelAndView addPage(ModelAndView model){

        model.setViewName("image-add");
        return model;
    }

    public JsonData add(MultipartFile file){
        return null ;
    }

    @RequestMapping(value = "image_list" , method = RequestMethod.GET)
    @ResponseBody
    public Map<String,Object> image_list(@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                         @RequestParam(value = "pageSize",defaultValue = "10") int pageSize){
        Map<String,Object> map = Maps.newLinkedHashMap();
        PageInfo pageInfo = iFileService.list(pageNum, pageSize);
        if (pageInfo == null){
            map.put("code",0);
            map.put("msg","未查找到图片信息");
            map.put("count", StringUtils.EMPTY);
            map.put("data",StringUtils.EMPTY);
            return map ;
        }
        map.put("code",0);
        map.put("msg","未查找到图片信息");
        map.put("count", pageInfo.getTotal());
        map.put("data",pageInfo.getList());
        return map ;
    }



}
